<?php


class Simpleshop_Model_DbTable_Basket_Row extends WSB_Db_Row
{

	/**
	 * Setze Artikel
	 *
	 * @param Simpleshop_Model_DbTable_Article_Row $article
	 */
	public function setArticle(Simpleshop_Model_DbTable_Article_Row $article)
	{
		$this->_data['article'] = $article->toArray();
	}

	/**
	 * Gib den zugehoerigen Artikel zurueck.
	 *
	 * @return Simpleshop_Model_DbTable_Article_Row
	 *
	 */
	public function getArticle()
	{
		if(isset($this->_data['article']) && is_array($this->_data['article'])) {
			$config = array(
				'data' => $this->_data['article'],
				'readOnly' => true
			);
			return new Simpleshop_Model_DbTable_Article_Row($config);
		}
		return null;
	}

	/**
	 * @return string
	 */
	public function getTitle()
	{
		return $this->getArticleTitle();
	}

	/**
	 * @return integer
	 */
	public function getArticleId()
	{
		return isset($this->_data['article']['id']) ? $this->_data['article']['id'] : 0 ;
	}

	/**
	 * @return string
	 */
	public function getArticleTitle()
	{
		return isset($this->_data['article']['title']) ? $this->_data['article']['title'] : '' ;
	}

	/**
	 * @return string
	 */
	public function getArticleNumber()
	{
		return isset($this->_data['article']['article_number']) ? $this->_data['article']['article_number'] : '' ;
	}

	/**
	 * @return float
	 */
	public function getPrice()
	{
		$article = $this->getArticle();
		if($article instanceof Simpleshop_Model_DbTable_Article_Row) {
			return $article->getPrice();
		}
		return floatval(0);
	}

	/**
	 * @return float
	 */
	public function getSubtotal()
	{
		$article = $this->getArticle();
		if($article instanceof Simpleshop_Model_DbTable_Article_Row) {
			return floatval($this->getQuantity() * $article->getPrice());
		}
		return floatval(0);
	}

	/**
	 * @return integer
	 */
	public function getQuantity()
	{
		return intval($this->quantity);
	}

}